using Game.Core;
using Game.Main.Model;
using Game.Manager;
using SimpleJSON;
using UnityEngine;

namespace Game.Component
{
	public class WaterPipeItem : BaseItem
	{
		private float minX = -2.4f;

		private float maxX = 0.6f;

		private float minY = 7.5f;

		private float maxY = 9f;

		private Vector2 lastTouchPoint;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			if (data.modelX != 0f || data.modelY != 0f)
			{
				model.localPosition = new Vector3(data.modelX, data.modelY, model.localPosition.z);
			}
		}

		public override void TouchDown(TouchEventData touchEventData)
		{
			lastTouchPoint = touchEventData.curPos;
			Singleton<AudioManager>.Instance.PlayAudio("sound_car_water", true, GetAudioPlayer());
			PlayDragEffect();
		}

		public override void TouchUp(TouchEventData touchEventData)
		{
			RemoveAudioPlayer();
			StopDragEffect();
		}

		public override void TouchMove(TouchEventData touchEventData)
		{
			float num = model.localPosition.x + (touchEventData.curPos.x - lastTouchPoint.x);
			float num2 = model.localPosition.y + (touchEventData.curPos.y - lastTouchPoint.y);
			if (num < minX)
			{
				num = minX;
			}
			else if (num > maxX)
			{
				num = maxX;
			}
			if (num2 < minY)
			{
				num2 = minY;
			}
			else if (num2 > maxY)
			{
				num2 = maxY;
			}
			model.localPosition = new Vector3(num, num2, model.localPosition.z);
			lastTouchPoint = touchEventData.curPos;
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["34"] = model.localPosition.x.ToString("F3");
			obj["39"] = model.localPosition.y.ToString("F3");
		}
	}
}
